<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-tabs class="tab" v-model="activeName">
          <el-tab-pane label="销售额" name="saleNum"></el-tab-pane>
          <el-tab-pane label="访问量" name="VisiterNum"></el-tab-pane>
        </el-tabs>
        <!-- 右侧内容 -->
        <div class="right">
          <span @click="setDate">今日</span>
          <span @click="setWeek">本周</span>
          <span @click="setMonth">本月</span>
          <span @click="setYear">本年</span>
          <el-date-picker
            v-model="date"
            class="date"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="mini"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </div>
      </div>
      <div>
        <el-row :gutter="10">
          <el-col :span="18">
            <div class="chartszhu" ref="zhu"></div>
          </el-col>
          <el-col :span="6">
            <div style="font-size: 16px; font-weight: 700; padding-top: 4px">
              门店{{ title }}排名
            </div>
            <ul class="rightList">
              <li>
                <span class="Lindex">1</span>
                <span>蜜雪冰城</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lindex">2</span>
                <span>奈雪の茶</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lindex">3</span>
                <span>都可CoCo</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lin">4</span>
                <span>一点点奶茶</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lin">5</span>
                <span>茶百道</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lin">6</span>
                <span>益禾堂</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lin">7</span>
                <span>书亦烧仙草</span>
                <span class="Rnum">5121</span>
              </li>
              <li>
                <span class="Lin">8</span>
                <span>DAKASI大卡司</span>
                <span class="Rnum">5121</span>
              </li>
            </ul>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";
import dayjs, { Dayjs } from "dayjs";
export default {
  data() {
    return {
      activeName: "saleNum",
      myCharts: null,
      date: "",
    };
  },
  computed: {
    title() {
      return this.activeName == "saleNum" ? "销售额" : "访问量";
    },
  },
  methods: {
    setDate() {
      const day = dayjs().format("YYYY-MM-DD");
      this.date = [day, day];
    },
    setWeek() {
      const start = dayjs().day(1).format("YYYY-MM-DD");
      const end = dayjs().day(7).format("YYYY-MM-DD");
      this.date = [start, end];
    },
    setMonth() {
      const start = dayjs().startOf("month").format("YYYY-MM-DD");
      const end = dayjs().endOf("month").format("YYYY-MM-DD");
      this.date = [start, end];
    },
    setYear() {
      const start = dayjs().startOf("year").format("YYYY-MM-DD");
      const end = dayjs().endOf("year").format("YYYY-MM-DD");
      this.date = [start, end];
    },
  },
  mounted() {
    this.myCharts = echarts.init(this.$refs.zhu);
    this.myCharts.setOption({
      title: {
        text: "销售额趋势",
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "Direct",
          type: "bar",
          barWidth: "60%",
          data: [10, 52, 200, 334, 390, 330, 220, 150, 351, 224, 84, 264],
        },
      ],
    });
  },
  watch: {
    title() {
      this.myCharts.setOption({
        title: {
          text: this.title,
        },
      });
    },
  },
};
</script>

<style >
>>> .el-card__header {
  border-bottom: none;
}
.clearfix {
  position: relative;
  display: flex;
  justify-content: space-between;
}
.tab {
  width: 100%;
}
.right {
  position: absolute;
  right: 20px;
}
.right span {
  margin: 0 10px;
}
.date {
  width: 300px !important;
}
.chartszhu {
  width: 100%;
  height: 350px;
}

.rightList {
  list-style: none;
  width: 100%;
  height: 350px;
  padding-left: 0;
  margin-top: 15px;
}
.rightList li {
  height: 40px;
}
.Lindex {
  float: left;
  width: 15px;
  height: 15px;
  background-color: black;
  color: white;
  border-radius: 50%;
  text-align: center;
  margin-right: 10px;
}
.Rnum {
  float: right;
  margin-right: 10px;
}
.Lin {
  float: left;
  width: 15px;
  height: 15px;
  /* background-color: black; */
  /* color: white; */
  /* border-radius: 50%; */
  text-align: center;
  margin-right: 10px;
}
</style>